package com.example.demo6.SQLite;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

@Database(entities ={User.class,LostGoods.class,PickupGoods.class},version = 1,exportSchema = false)
public abstract class MyDatabase extends RoomDatabase {
    private static final String DATABASE_NAME = "my_db";

    private static MyDatabase databaseInstance;

    public static synchronized MyDatabase getInstance(Context context)
    {
        if(databaseInstance == null)
        {
            databaseInstance = Room
                    .databaseBuilder(context.getApplicationContext(), MyDatabase.class, DATABASE_NAME)
                    .build();
            //Android的官方文档指出，不建议使用allowMainThreadQueries()，因为它可能会长时间锁定UI并触发ANR。.allowMainThreadQueries()
        }
        return databaseInstance;
    }

    public abstract UserDao userDao();
    public abstract LostGoodsDao lostGoodsDao();
    public abstract PickupGoodsDao pickupGoodsDao();
}
